Skip to content

fix: allow API to run against a read-only /ref mount#30

Merged
lewisjared merged 5 commits intomainfrom
fix/readonly-ref-mount
Apr 13, 2026
Merged

fix: allow API to run against a read-only /ref mount#30
lewisjared merged 5 commits intomainfrom
fix/readonly-ref-mount

Conversation

@lewisjared
Copy link
Copy Markdown
Contributor

Summary

Resolves #29. Lets climate-ref-frontend run against a read-only /ref PVC without init-container workarounds.

  • Read-only SQLite: new REF_READ_ONLY_DATABASE setting opens the configured SQLite DB via sqlite:///file:<path>?mode=ro&immutable=1&uri=true, so SQLite does not attempt to create a WAL/journal sidecar. Plumbed through main.py and api/deps.py.
  • climate-ref bump: >=0.13.0,<0.14 so the API's bundled alembic scripts match the revision the chart's migrate Job writes. uv.lock regenerated.
  • Migration check aligned with ref db status: replaced the hand-rolled probe in get_database with a head-vs-current comparison using alembic.script.ScriptDirectory (the same pattern the CLI uses in climate_ref.cli.db). When the DB is stamped with a revision this image doesn't know, we log a warning and continue rather than raising — migration ownership stays with the CLI/Job.
  • Dockerfile guard: switched the second uv sync to --no-editable, and added a build-time assertion that climate_ref_core/pycmec/cv_cmip7_aft.yaml is present in the installed wheel so missing package data fails the build instead of the pod at startup.

Test plan

  • uv run pytest src tests — 185 passed, 1 xfailed
  • uv run ruff check src tests && uv run ruff format --check src tests
  • uv run mypy src
  • New tests in tests/test_core/test_ref.py:
    • test_get_database_read_only_rejects_writes — asserts writes on a read_only=True DB raise OperationalError
    • test_get_database_tolerates_unknown_revision — DB stamped with an unknown alembic revision doesn't raise
  • Manual: docker build -t ref-app:test .; docker run -v $PWD/backend/tests/test-data/.../db:/ref:ro -e REF_CONFIGURATION=/ref -e REF_READ_ONLY_DATABASE=true ref-app:test; curl /api/v1/executions
  • Deploy image to the climate-ref-aft chart with readOnly: true on the /ref mount (tracked in chore: align REF configuration and migrate to SemVer climate-ref-aft#7)

- Add REF_READ_ONLY_DATABASE setting that opens SQLite via
  file: URI with mode=ro&immutable=1, avoiding WAL/journal writes.
- Bump climate-ref to >=0.13.0,<0.14 so bundled alembic scripts
  match the migrations applied by the climate-ref-aft chart.
- Replace the hand-rolled revision check with a status check
  modelled on `ref db status`; tolerate DBs stamped by a newer
  CLI instead of raising.
- Harden the Dockerfile: install climate-ref(-core) via a
  non-editable uv sync and fail the build early if
  climate_ref_core/pycmec/cv_cmip7_aft.yaml is missing from
  the installed wheel.
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 13, 2026

Deploy Preview for climate-ref canceled.

Name Link
🔨 Latest commit db16f2b
🔍 Latest deploy log https://app.netlify.com/projects/climate-ref/deploys/69dc78b693dec6000862e88f

@lewisjared lewisjared changed the title fix: allow API to run against a read-only /ref mount (#29) fix: allow API to run against a read-only /ref mount Apr 13, 2026
- climate-ref >=0.13.1,<0.14: use upstream Database.from_config(read_only=True)
  and Database.migration_status helpers; drop ref-app's _build_readonly_database
  and _check_migration_status shims. Packaging test in climate-ref-core 0.13.1
  also lets us drop the Dockerfile pycmec-yaml build guard.
- vite >=7.3.2 <8: security fix; vite 8's manualChunks type-break blocks
  bumping further without a config rewrite.
- pydantic-settings >=2.13.1.
- Drop tenacity (unused) and python-multipart (transitive via fastapi[standard]).
@lewisjared lewisjared merged commit 38e562d into main Apr 13, 2026
8 checks passed
@lewisjared lewisjared deleted the fix/readonly-ref-mount branch April 13, 2026 05:09
lewisjared added a commit to Climate-REF/climate-ref-aft that referenced this pull request Apr 13, 2026
ref-app v0.3.1 (Climate-REF/ref-app#30) ships cv_cmip7_aft.yaml and read-only DB support, and bumps its bundled climate-ref to v0.13.1. Track the new appVersion and update default image tags.
lewisjared added a commit to Climate-REF/climate-ref-aft that referenced this pull request Apr 13, 2026
ref-app v0.3.1 (Climate-REF/ref-app#30) ships cv_cmip7_aft.yaml and read-only DB support, and bumps its bundled climate-ref to v0.13.1. Track the new appVersion and update default image tags.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API startup requires /ref to be mounted read-write (cv_cmip7_aft.yaml missing + sqlite journal)

1 participant